package com.woniu.publisher;

import com.woniu.utils.ConstantUtil;
import com.woniu.utils.RabbitMessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class UpdateRegistrationPublisher {
    @Resource
    private RabbitTemplate rabbitTemplate;
    @Resource
    private RabbitMessageUtil rabbitMessageUtil;
    public void send(String msg,Integer ttl){
        rabbitTemplate.setConfirmCallback(rabbitMessageUtil);
        rabbitTemplate.setReturnsCallback(rabbitMessageUtil);
        log.info("delay生产者发送消息：{}",msg);
        rabbitTemplate.convertAndSend(ConstantUtil.EXCHANGE_CHECK_ORDER_STATUS
                , ConstantUtil.ROUTING_KEY_DELAY
                ,msg,
                message -> {
                    message.getMessageProperties().setDelay(ttl);
                    return message;
                }
        );
    }
}
